using BootstrapBlazor.Components;
using JinShun.OA.UI.Dtos.Post;
using JinShun.OA.UI.IServer.Navigation;
using JinShun.OA.UI.IServer.Post;
using JinShun.OA.UI.Models;
using JinShun.OA.UI.Services.Navigation;
using Microsoft.AspNetCore.Components;
using System.Diagnostics.CodeAnalysis;

namespace JinShun.OA.UI.Components.Pages
{
    public partial class Post
    {
        [Inject]
        [NotNull]
        private IPost PostManager { get; set; }

        private   async Task<QueryData<PostModel>> OnQueryAsync(QueryPageOptions options)
        {
            List<PostModel> Posts = await PostManager.GetPostsAsync();

            // 处理模糊查询
            if (options.Searches.Any())
            {
                Posts = (Posts.Where(options.Searches.GetFilterFunc<PostModel>(FilterLogic.Or))).ToList();
            }

            //  处理 Filter 高级搜索
            if (options.CustomerSearches.Any() || options.Filters.Any())
            {
                Posts = (Posts.Where(options.CustomerSearches.Concat(options.Filters).GetFilterFunc<PostModel>())).ToList();
            }

            return await  Task.FromResult(new QueryData<PostModel>()
            {
                IsFiltered = true,
                IsSearch = true,
                IsSorted = true,
                Items = (IEnumerable<PostModel>)Posts
            });
        }
    }
}